package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description：
 * User：user
 * DATE:2021-10-29
 * Time:20:12
 */
public class AddOperation implements  IOPeration{

    @Override
    public void work(BookList bookList){
        System.out.println("新增书籍");
        System.out.println("请输入图书的名字：");
        String name = scanner.nextLine();
        System.out.println("请输入图书的作者：");
        String author = scanner.nextLine();
        System.out.println("请输入图书的类型：");
        String type = scanner.nextLine();
        System.out.println("请输入图书的价格：");
        int price = scanner.nextInt();

        Book book = new Book(name,author,price,type);

        //查重操作确定系统中没有这本书
        int size = bookList.getUsedSize();
        for (int i = 0; i < size; i++) {
            Book bookCurrent = bookList.getBook(i);
            if(bookCurrent.getName().equals(name)){
                System.out.println("书架上有这本书");
                return;
            }
        }
        bookList.setBooks(size,book);
        bookList.setUsedSize(size + 1);
        System.out.println("新增成功！");
    }
}
